package biz.obake.team.touchprotector;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.os.Vibrator;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import biz.obake.team.android.a;
import biz.obake.team.touchprotector.tpas.TPAccessibilityService;

public class c {
    public static int a(int i, String str) {
        String[] stringArray = a.a().getResources().getStringArray(i);
        int i2 = 0;
        if (str == null) {
            while (i2 < stringArray.length) {
                if (stringArray[i2] == null) {
                    return i2;
                }
                i2++;
            }
            return -1;
        }
        while (i2 < stringArray.length) {
            if (str.equals(stringArray[i2])) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public static int b(int i) {
        return a.a().getResources().getStringArray(i).length;
    }

    public static String c(int i, int i2) {
        return a.a().getResources().getStringArray(i)[i2];
    }

    public static String d(byte[] bArr) {
        StringBuilder sb = new StringBuilder();
        int length = bArr.length;
        for (int i = 0; i < length; i++) {
            sb.append(String.format("%02x", new Object[]{Byte.valueOf(bArr[i])}));
        }
        return sb.toString();
    }

    public static boolean e() {
        if (Build.VERSION.SDK_INT < 23) {
            return true;
        }
        return Settings.canDrawOverlays(a.a());
    }

    public static void f() {
        a.a().sendBroadcast(new Intent("android.intent.action.CLOSE_SYSTEM_DIALOGS"));
    }

    public static float g(float f) {
        return f * a.a().getResources().getDisplayMetrics().density;
    }

    public static String h() {
        StringBuilder sb = new StringBuilder();
        sb.append("Touch Protector: " + m() + "(" + l() + ")\n");
        sb.append("Package: biz.obake.team.touchprotector\n");
        StringBuilder sb2 = new StringBuilder();
        sb2.append("NavigationBar: ");
        sb2.append(n());
        sb2.append("\n");
        sb.append(sb2.toString());
        sb.append("TPAS: " + TPAccessibilityService.i() + "\n");
        return sb.toString();
    }

    public static String i() {
        StringBuffer stringBuffer = new StringBuffer();
        for (AccessibilityServiceInfo id : ((AccessibilityManager) a.a().getSystemService("accessibility")).getEnabledAccessibilityServiceList(-1)) {
            stringBuffer.append(id.getId() + "\n");
        }
        return stringBuffer.toString();
    }

    public static String j() {
        StringBuilder sb = new StringBuilder();
        sb.append("Device: " + Build.DEVICE + "\n");
        sb.append("Model: " + Build.MODEL + "\n");
        sb.append("SDK: " + Build.VERSION.SDK_INT + "\n");
        sb.append("OSVer: " + Build.VERSION.RELEASE + "\n");
        sb.append("Build: " + Build.DISPLAY + "\n");
        sb.append("Manufacturer: " + Build.MANUFACTURER + "\n");
        sb.append("Brand: " + Build.BRAND + "\n");
        return sb.toString();
    }

    public static String k() {
        int myPid = Process.myPid();
        for (ActivityManager.RunningAppProcessInfo next : ((ActivityManager) a.a().getSystemService("activity")).getRunningAppProcesses()) {
            if (next.pid == myPid) {
                return next.processName;
            }
        }
        return "";
    }

    public static int l() {
        try {
            return a.a().getPackageManager().getPackageInfo(a.a().getPackageName(), 0).versionCode;
        } catch (PackageManager.NameNotFoundException unused) {
            return 0;
        }
    }

    public static String m() {
        try {
            return a.a().getPackageManager().getPackageInfo(a.a().getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException unused) {
            return "?";
        }
    }

    public static boolean n() {
        Resources resources = a.a().getResources();
        int identifier = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        return identifier > 0 && resources.getBoolean(identifier);
    }

    public static boolean o(String str) {
        for (AccessibilityServiceInfo id : ((AccessibilityManager) a.a().getSystemService("accessibility")).getEnabledAccessibilityServiceList(-1)) {
            String id2 = id.getId();
            if (id2 != null) {
                if (id2.startsWith(str + "/")) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean p() {
        return 2 == a.a().getResources().getConfiguration().orientation;
    }

    public static boolean q() {
        int intExtra = a.a().registerReceiver((BroadcastReceiver) null, new IntentFilter("android.intent.action.BATTERY_CHANGED")).getIntExtra("status", -1);
        return intExtra == 2 || intExtra == 5;
    }

    public static boolean r() {
        return ((PowerManager) a.a().getSystemService("power")).isScreenOn();
    }

    public static boolean s() {
        return Build.VERSION.SDK_INT >= 23 ? Looper.getMainLooper().isCurrentThread() : Looper.getMainLooper().getThread() == Thread.currentThread();
    }

    public static float t(float f) {
        return f / a.a().getResources().getDisplayMetrics().density;
    }

    public static void u() {
        if (Build.VERSION.SDK_INT >= 23) {
            a a2 = a.a();
            Intent intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:" + a2.getPackageName()));
            intent.setFlags(268435456);
            a2.startActivity(intent);
        }
    }

    public static int v(String str) {
        a a2 = a.a();
        return a2.getResources().getIdentifier(str, "id", a2.getPackageName());
    }

    public static String w(int i) {
        if (i == 0) {
            return null;
        }
        return a.a().getResources().getString(i);
    }

    public static void x() {
        String l = biz.obake.team.touchprotector.g.a.l("vibrate_length");
        if (!"none".equals(l)) {
            ((Vibrator) a.a().getSystemService("vibrator")).vibrate(Long.parseLong(l));
        }
    }
}
